#!/usr/bin/perl -w # for syntax highlighting
# CSS-V1

use gri_database;
use Data::Dumper;

sub mm_form_docrepos_admin_add_section_populate {
my ($sec_name,$sec_parent,$sec_title,$sec_description,$sec_readers,$sec_publishers)=@_;

	my $db_dir=$::GRI_FRONTEND->get_global_directory("database");
	my $DB=new gri_database("$db_dir/gri.db");
	$sec_name="" if $sec_name eq "?sec_name - not defined?";
	$sec_parent="" if $sec_parent eq "?sec_parent - not defined?";
	$sec_title="" if $sec_title eq "?sec_title - not defined?";
	$sec_description="" if $sec_description eq "?sec_description - not defined?";
	$sec_readers="" if $sec_readers eq "?sec_readers - not defined?";
	$sec_publishers="" if $sec_publishers eq "?sec_publishers - not defined?";
	$sec_attributes="" if $sec_attributes eq "?sec_attributes - not defined?";

	$sec_name=hex_to_string($sec_name);
	$sec_parent=hex_to_string($sec_parent);
	$sec_title=hex_to_string($sec_title);
	$sec_description=hex_to_string($sec_description);
	$sec_readers=hex_to_string($sec_readers);
	$sec_publishers=hex_to_string($sec_publishers);
	$sec_attributes=hex_to_string($sec_attributes);
        # <INPUT TYPE=\"text\" VALUE=\"$sec_name\" NAME=\"name\" SIZE=\"60\" MAXLENGTH=\"40\" style=\"font-family:Arial; font-size:11px; background-color: #FFFFFF; border:1px double #E0E0E0;\">
my $s="
    <tr class=gri_headerrow>
      <td class=gri_cell colspan=3>New Document Repository Section Details
      </td>
    </tr>
    <tr class=gri_row>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Name:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <INPUT TYPE=\"text\" VALUE=\"$sec_name\" NAME=\"name\" SIZE=\"60\" MAXLENGTH=\"40\">
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Title:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <INPUT TYPE=\"text\" VALUE=\"$sec_title\" NAME=\"title\" SIZE=\"60\" MAXLENGTH=\"80\">
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Description:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
        <TEXTAREA NAME=\"description\" COLS=60 ROWS=5>$sec_description</TEXTAREA>
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Attributes:</font></td>
      <td>&nbsp;&nbsp;&nbsp;</td>
      <td align=left>
        <INPUT TYPE=\"text\" SIZE=\"60\" NAME=\"attributes\" VALUE=\"$sec_attributes\">
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Parent Section:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>
	<SELECT NAME=\"type\" SIZE=\"3\">\n";
	# Now we need a list of all existing sections and a special "_TOP_LEVEL_ entry too
	my ($rc,$lref)=$DB->list_sections();
	if($rc==-1) {
		$s.="<OPTION value=\"\" selected=\"selected\">Error: Unable to check groups</OPTION>\n";
	} else {
		for my $cc (@$lref) {
			$s.="<OPTION value=\"html\">$cc</OPTION>\n";
		}
	}
	$s.="</SELECT>
      </td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Reader Groups:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>\n";

    # Add the tickboxes for the reader/publisher groups...
	my ($rc2,$lref2)=$DB->list_groups();
	for my $cg (@$lref2) {
		my ($_l,$_h)=$DB->get_group(group=>$cg);
		$s.="<INPUT TYPE=CHECKBOX NAME=\"reader_$cg\">$cg - $_h->{description}<BR>\n";
	}
	$s.="\n</td></tr>
    <tr class=gri_row>
      <td class=gri_cell colspan=3>&nbsp;</td>
    </tr>
    <tr class=gri_row>
      <td class=gri_cell><font class=stdtextlarge>Publisher Groups:</font></td>
      <td class=gri_cell>&nbsp;&nbsp;&nbsp;</td>
      <td class=gri_cell>\n";

    # Add the tickboxes for the reader/publisher groups...
	for my $cg (@$lref2) {
		my ($_l,$_h)=$DB->get_group(group=>$cg);
		$s.="<INPUT TYPE=CHECKBOX NAME=\"publisher_$cg\">$cg - $_h->{description}<BR>\n";
	}
	$s.="\n</td></tr>\n";
	return $s;
}

1;

